import pandas as pd
from parsers.base_parser import BaseParser
import logging
from core.normalizer import normalize_account_info, normalize_transaction_flow

logger = logging.getLogger(__name__)

class Parser003(BaseParser):
    def parse(self, file_path):
        sheets = self.read_excel_sheets(file_path)
        if not sheets:
            return pd.DataFrame(), pd.DataFrame()

        # 假设开户在Sheet1，流水在Sheet2
        account_info = {}
        transaction_data = []

        if len(sheets) >= 1:
            df_account = list(sheets.values())[0]
            account_info = {
                '账号': df_account.iloc[0, 0],
                '开户名': df_account.iloc[0, 1],
                '开户行名称': '中国银行',
                '证件号码': df_account.iloc[0, 2],
            }

        if len(sheets) >= 2:
            df_flow = list(sheets.values())[1]
            for _, row in df_flow.iterrows():
                transaction_data.append({
                    '日期': row[0],
                    '摘要/用途': row[1],
                    '收支方向': row[2],
                    '金额': row[3],
                    '余额': row[4],
                    '对方账户信息': row[5],
                })

        account_df = normalize_account_info(account_info)
        transaction_df = normalize_transaction_flow(transaction_data)

        return account_df, transaction_df